
package com.scs.application.modules.upms.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.TreeServiceImpl;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.upms.entity.Area;
import com.scs.application.modules.upms.mapper.AreaMapper;
import com.scs.application.modules.upms.request.AreaQueryRequest;
import com.scs.application.modules.upms.service.AreaService;
import com.scs.application.modules.upms.vo.AreaVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* 行政区划 service 实现
*/
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class AreaServiceImpl extends TreeServiceImpl<AreaMapper, Area> implements AreaService {

    @Override
    public List<Area> list(AreaQueryRequest request) {
        List<Area> list = this.list(Wrappers.<Area>query()
                .eq(StringUtils.isNotBlank(request.getId()), "id", request.getId())
                .like(StringUtils.isNotBlank(request.getName()), "name", request.getName())
            .orderByAsc("sort")
        );

        return list;
    }

    @Override
    public IPage<AreaVO> page(AreaQueryRequest request) {
        return  this.baseMapper.page(request.getPage(), request);
    }

}
